<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <script src="https://cdn.bootcss.com/socket.io/2.2.0/socket.io.slim.js"></script>
  <script src="https://cdn.bootcss.com/vue/2.5.16/vue.min.js"></script>
  <title>Document</title>
</head>

<body>
  <div id="app">
    <img :src="aaa" width="300" height="300" alt="">
    <input type="text" v-model="img">
    <button type="button" @click="button">提交</button>
  </div>
</body>
<script>
  const log = console.log;

  window.onload = function () {
    // init
    const socket = io('/chat', {

      // 实际使用中可以在这里传递参数
      query: {
        room: 'demo',
        userId: `client_${Math.random()}`,
      },

      transports: ['websocket']
    });

    socket.on('connect', () => {
      const id = socket.id;

      log('#connect,', id, socket);

      // 监听自身 id 以实现 p2p 通讯
      socket.on(id, msg => {
        log('#receive,', msg);
      });
    });

    // 接收在线用户信息
    socket.on('online', msg => {
      log('#online,', msg);
    });

    // 系统事件
    socket.on('disconnect', msg => {
      log('#disconnect', msg);
    });

    socket.on('disconnecting', () => {
      log('#disconnecting');
    });

    socket.on('error', () => {
      log('#error');
    });

    window.socket = socket;
  };
  new Vue({
    el: '#app',
    data: {
      aaa: '',
      img: ''
    },
    mounted() {

    },

    methods: {
      button: function () {

      }
    },
  })
</script>

</html>